package com.nhjf.admin.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

import com.nhjf.admin.common.util.SysProperties;
import com.nhjf.common.util.Properties.MobilProperties;

public class BuildIndexPageUtil {

	public static void buildIndexPage(StringBuffer html1, StringBuffer html2,
			StringBuffer html3,StringBuffer html4,StringBuffer html5,StringBuffer html6, String indexVilidate) {
		String content;
		try {
			URL url1 = new URL(SysProperties.getInstance().get(
					"buildHtmlPathOne")
					+ "?indexVilidate=" + indexVilidate);
			URLConnection uc1 = url1.openConnection();
			InputStream is1 = uc1.getInputStream();
			BufferedReader reader1 = new BufferedReader(new InputStreamReader(
					is1));
			while ((content = reader1.readLine()) != null) {
				html1.append(content);
			}
			is1.close();
		} catch (MalformedURLException e) {
			html1.append("error");
			e.printStackTrace();

		} catch (IOException e) {
			html1.append("error");
			e.printStackTrace();

		}

		try {
			URL url2 = new URL(SysProperties.getInstance().get(
					"buildHtmlPathTwo")
					+ "?indexVilidate=" + indexVilidate);
			URLConnection uc2 = url2.openConnection();
			InputStream is2 = uc2.getInputStream();
			BufferedReader reader2 = new BufferedReader(new InputStreamReader(
					is2));
			while ((content = reader2.readLine()) != null) {
				html2.append(content);
			}
			is2.close();
		} catch (MalformedURLException e) {
			e.printStackTrace();
			html2.append("error");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			html2.append("error");
		}

		try {
			URL url3 = new URL(SysProperties.getInstance().get(
					"buildHtmlPathThree")
					+ "?indexVilidate=" + indexVilidate);
			URLConnection uc3 = url3.openConnection();
			InputStream is3 = uc3.getInputStream();
			
			BufferedReader reader3 = new BufferedReader(new InputStreamReader(
					is3));
			while ((content = reader3.readLine()) != null) {
				html3.append(content);
			}
			is3.close();
		} catch (MalformedURLException e) {
			e.printStackTrace();
			html3.append("error");
		} catch (IOException e) {
			e.printStackTrace();
			html3.append("error");
		}	
		
		//移动端
		/**modify by Daven 2016-04-13 内容：添加了html4,5,6三个参数**/
		try {
			URL url1 = new URL(MobilProperties.getInstance().get(
					"mobileCacheUrlOne")+"/service/index");
			URLConnection uc1 = url1.openConnection();
			InputStream is1 = uc1.getInputStream();			
			BufferedReader reader1 = new BufferedReader(new InputStreamReader(
					is1,"utf-8"));
			while ((content = reader1.readLine()) != null) {
				html4.append(content);
			}
			is1.close();
		} catch (MalformedURLException e) {
			html4.append("error");
			e.printStackTrace();

		} catch (IOException e) {
			html4.append("error");
			e.printStackTrace();

		}

		try {
			URL url2 = new URL(MobilProperties.getInstance().get(
					"mobileCacheUrlTwo") +"/service/index" );
			URLConnection uc2 = url2.openConnection();
			InputStream is2 = uc2.getInputStream();
			BufferedReader reader2 = new BufferedReader(new InputStreamReader(
					is2,"utf-8"));
			while ((content = reader2.readLine()) != null) {
				html5.append(content);
			}
			is2.close();
		} catch (MalformedURLException e) {
			e.printStackTrace();
			html5.append("error");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			html5.append("error");
		}

		try {
			URL url3 = new URL(MobilProperties.getInstance().get(
					"mobileCacheUrlThree")+"/service/index");
			URLConnection uc3 = url3.openConnection();
			InputStream is3 = uc3.getInputStream();
			BufferedReader reader3 = new BufferedReader(new InputStreamReader(
					is3,"utf-8"));
			while ((content = reader3.readLine()) != null) {
				html6.append(content);
			}
			is3.close();
		} catch (MalformedURLException e) {
			e.printStackTrace();
			html6.append("error");
		} catch (IOException e) {
			e.printStackTrace();
			html6.append("error");
		}		
		
	}	
	
}
